﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace Deflection
{
    class BackGroundElement : GameObject
    {
        Color color = Color.White;
        Color inverse;
        Vector2 direction;
        float speed;

        public static Texture2D BackgroundSprite { get; set; }

        public BackGroundElement(Vector2 position, Color color, Vector2 direction, float speed) : base(position)
        {
            this.color = color;
            this.inverse = Invert(color);
            this.direction = direction;
            this.speed = speed;
        }

        public void Update(GameTime gameTime, Vector2 direction)
        {
            if (gameTime.TotalGameTime.Milliseconds % 5000 == 0)
            {
                Random rand = new Random((int)gameTime.TotalGameTime.TotalMilliseconds * (int)this.position.X * (int)this.position.Y);
                inverse = new Color(rand.Next(256), rand.Next(256), rand.Next(256), rand.Next(200,256));
            }
            this.position.X += speed * direction.X;
            this.position.Y += speed * direction.Y;
            color = Color.Lerp(color, inverse, 0.05f);
            base.Update(gameTime);
        }

        public override void Draw(GameTime gameTime, SpriteBatch spriteBatch)
        {
            spriteBatch.Draw(BackGroundElement.BackgroundSprite, position, null, color, 0, new Vector2(BackGroundElement.BackgroundSprite.Bounds.Center.X, BackGroundElement.BackgroundSprite.Bounds.Center.Y), 0.5f, SpriteEffects.None, 1);
            
            base.Draw(gameTime, spriteBatch);
        }

        public override bool IsOffscreen()
        {
            if (this.position.Y < 0)
            {
                return true;
            }
            if (this.position.X < -25) // -25 so that bg stuff is removed when its past the edge of the screen, not when its on it
            {
                return true;
            }
            if (this.position.Y > GameParameters.SCREEN_SIZE.Y)
            {
                return true;
            }

            return false;
        
        }
    }
}
